<title>添加商品</title>
<?php

header("content-type:text/html; charset=utf-8");
$productname=$_POST['productname'];
$producttype=$_POST['producttype'];
$productprice=$_POST['productprice'];
$productcount=$_POST['productcount'];
$inputdate=$_POST['date'];
$inputname=$_POST['inputname'];

$sppicture=$_FILES['picture'];
$sppictureName=$sppicture['name'];
$string = explode(".",$sppictureName);
$type=$string['1'];
if($type=='jpg' || $type=='png' || $type=='jif'){

}else{ 
    header("refresh:2;url=subper.php");
    die('商品图片不合法，添加商品失败');
}
$sppictureTemp=$sppicture['tmp_name'];
$newfilename=mt_rand().".".$type;//应用随机数函数mt_rand() 来当文件名

$destination="uploads/".$newfilename;
$destination=iconv("UTF-8", "GBK", $destination);
move_uploaded_file($sppictureTemp,$destination);
$picturesrc="uploads/".$newfilename;
if($productname=="" ||$producttype=="" || $productprice=="" || $productcount=="" || $inputdate=="" || $inputname==""){
   header("refresh:2;url=subper.php");
   die("添加商品失败！请正确填写信息.....");
}

$serverLink=@mysql_connect("localhost","root","root") or die("连接服务器失败！程序中断");
mysql_query("set names 'utf-8'");
$dbLink= @mysql_select_db("supermarket") or die("打开supermarket数据库失败！程序中断");
$input="insert into product(productname,producttype,productprice,productcount,inputdate,inputname,picturesrc) 
values('$productname','$producttype','$productprice',$productcount,'$inputdate','$inputname','$picturesrc')";
$fhxx=mysql_query($input);
$fhxx1=mysql_affected_rows();
if($fhxx1>0){
    echo "商品添加成功";
    header("refresh:1;url=subper.php");
}else{
    echo "商品添加失败";
    header("refresh:1;url=subper.php");
}
mysql_close($serverLink);
?>